using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace Presentation
{
    public partial class frmTiepNhanHocSinh : Form
    {
        public frmTiepNhanHocSinh()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnGhi_Click(object sender, EventArgs e)
        {
            try
            {
                HocSinhDto hsDto = new HocSinhDto();
                LopHocDto lhDto;
                lhDto = (LopHocDto)cmbLopHoc.SelectedItem;
                hsDto.Ten = txtTen.Text;
                hsDto.NgaySinh = dtpNgaySinh.Value;
                hsDto.DiaChi = txtDiaChi.Text;
                hsDto.Toan = (double)nudToan.Value;
                hsDto.Ly = (double)nudLy.Value;
                hsDto.Hoa = (double)nudHoa.Value;
                hsDto.DTB = Math.Round(((hsDto.Toan
                                + (hsDto.Ly + hsDto.Hoa))
                                / 3), 2);
                hsDto.MaLop = lhDto.Ma;

                HocSinhBus hsBus = new HocSinhBus();
                hsBus.Them(hsDto);

                txtMa.Text = hsDto.Ma.ToString();
                txtDTB.Text = hsDto.DTB.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }

        private void frmTiepNhanHocSinh_Load(object sender, EventArgs e)
        {
            LopHocBus lhBus = new LopHocBus();
            IList ds;
            ds = lhBus.LayDanhSach();
            cmbLopHoc.DataSource = ds;
            cmbLopHoc.ValueMember = "Ma";
            cmbLopHoc.DisplayMember = "Ten";

        }

        private void txtTen_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((!char.IsLetter(e.KeyChar)
                   && !char.IsWhiteSpace(e.KeyChar)))
            {
                e.Handled = true;
            }
            if (char.IsControl(e.KeyChar))
            {
                e.Handled = false;
            }
        }
    }
}